package com.cxyd.modules.job.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cxyd.common.page.PageData;
import com.cxyd.common.constant.Constant;
import com.cxyd.common.service.impl.BaseServiceImpl;
import com.cxyd.modules.job.dao.SysJobLogDao;
import com.cxyd.modules.job.dto.SysJobLogDTO;
import com.cxyd.modules.job.entity.SysJobLogEntity;
import com.cxyd.modules.job.service.SysJobLogService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class SysJobLogServiceImpl extends BaseServiceImpl<SysJobLogDao, SysJobLogEntity> implements SysJobLogService {

    @Override
    public PageData<SysJobLogDTO> page(Map<String, Object> params) {
        IPage<SysJobLogEntity> page = baseDao.selectPage(
                getPage(params, Constant.CREATE_DATE, false),
                getWrapper(params)
        );
        return getPageData(page, SysJobLogDTO.class);
    }

    private QueryWrapper<SysJobLogEntity> getWrapper(Map<String, Object> params) {
        String jobName = (String) params.get("jobName");
        QueryWrapper<SysJobLogEntity> wrapper = new QueryWrapper<>();
        wrapper.like(StringUtils.isNotBlank(jobName), "job_name", jobName);
        return wrapper;
    }
}
